#define Escalas_cxx
#include "Escalas.h"
#include <map>

using namespace std;

double Escalas::getEscala(int r)
{

  // this is the luminosity for the periods from A to H
  double Ld = 35.0;
  double L0 = Ld; // inverted pb
  double esca;


  map<int,double> Nevents;
  map<int,double> Xsection; //in pb

  //qcd
  Nevents[105009]=1399184;
  Nevents[105010]=1395383;
  Nevents[105011]=1398078;
  Nevents[105012]=1397430;
  Nevents[105013]=1397401;
  Nevents[105014]=1391612;
  Nevents[105015]=1347654;
  Nevents[105016]=1125428;
  //top
  Nevents[105200]=999387;
  Nevents[105861]=199838;
  //dibosons
  Nevents[105985]=249837;
  Nevents[105986]=249725;
  Nevents[105987]=249830;
  //W->bb + jets
  Nevents[106280]=6499;
  Nevents[106281]=5500;
  Nevents[106282]=2997;
  Nevents[106283]=1500;
  //Z->ee + jets
  Nevents[107650]=303966;
  Nevents[107651]=63440;
  Nevents[107652]=18997;
  Nevents[107653]=5499;
  Nevents[107654]=1499;
  Nevents[107655]=500;
  //Z->mumu + jets
  Nevents[107660]=303947;
  Nevents[107661]=62996;
  Nevents[107662]=18993;
  Nevents[107663]=5497;
  Nevents[107664]=1499;
  Nevents[107665]=499;
  //Z->tautau + jets
  Nevents[107670]=302959;
  Nevents[107671]=62981;
  Nevents[107672]=18993;
  Nevents[107673]=5497;
  Nevents[107674]=1499;
  Nevents[107675]=499;

  double zll0=(Nevents[107650]+Nevents[107660]+Nevents[107670])/3.0;
  double zll1=(Nevents[107651]+Nevents[107661]+Nevents[107671])/3.0;
  double zll2=(Nevents[107652]+Nevents[107662]+Nevents[107672])/3.0;
  double zll3=(Nevents[107653]+Nevents[107663]+Nevents[107673])/3.0;
  double zll4=(Nevents[107654]+Nevents[107664]+Nevents[107674])/3.0;
  double zll5=(Nevents[107655]+Nevents[107665]+Nevents[107675])/3.0;
  Nevents[107650]=zll0; Nevents[107660]=zll0; Nevents[107670]=zll0;
  Nevents[107651]=zll0; Nevents[107661]=zll1; Nevents[107671]=zll1;
  Nevents[107652]=zll0; Nevents[107662]=zll2; Nevents[107672]=zll2;
  Nevents[107653]=zll0; Nevents[107663]=zll3; Nevents[107673]=zll3;
  Nevents[107654]=zll0; Nevents[107664]=zll4; Nevents[107674]=zll4;
  Nevents[107655]=zll0; Nevents[107665]=zll5; Nevents[107675]=zll5;


  //W->enu + jets
  Nevents[107680]=1381531;
  Nevents[107681]=257958;
  Nevents[107682]=188896;
  Nevents[107683]=49978;
  Nevents[107684]=12991;
  Nevents[107685]=3449;
  //W->munu + jets
  Nevents[107690]=1386038;
  Nevents[107691]=254959;
  Nevents[107692]=187860;
  Nevents[107693]=49887;
  Nevents[107694]=12991;
  Nevents[107695]=3498;
  //W->taunu + jets
  Nevents[107700]=1364841;
  Nevents[107701]=254753;
  Nevents[107702]=187946;
  Nevents[107703]=49972;
  Nevents[107704]=12996;
  Nevents[107705]=3498;

  double wlnu0=(Nevents[107680]+Nevents[107690]+Nevents[107700])/3.0;
  double wlnu1=(Nevents[107681]+Nevents[107691]+Nevents[107701])/3.0;
  double wlnu2=(Nevents[107682]+Nevents[107692]+Nevents[107702])/3.0;
  double wlnu3=(Nevents[107683]+Nevents[107693]+Nevents[107703])/3.0;
  double wlnu4=(Nevents[107684]+Nevents[107694]+Nevents[107704])/3.0;
  double wlnu5=(Nevents[107685]+Nevents[107695]+Nevents[107705])/3.0;
  Nevents[107680]=wlnu0; Nevents[107690]=wlnu0; Nevents[107700]=wlnu0;
  Nevents[107681]=wlnu1; Nevents[107691]=wlnu1; Nevents[107701]=wlnu1;
  Nevents[107682]=wlnu2; Nevents[107692]=wlnu2; Nevents[107702]=wlnu2;
  Nevents[107683]=wlnu3; Nevents[107693]=wlnu3; Nevents[107703]=wlnu3;
  Nevents[107684]=wlnu4; Nevents[107694]=wlnu4; Nevents[107704]=wlnu4;
  Nevents[107685]=wlnu5; Nevents[107695]=wlnu5; Nevents[107705]=wlnu5;

  //DrellYan_mumu
  Nevents[108319]=999503;
  //DrellYan_ee
  Nevents[108320]=999969;
  //DrellYanLowmM_mu3
  Nevents[108321]=499925;
  //DrellYanLowM_ee3
  Nevents[108322]=499931;
  //singletop
  Nevents[108340]=9993;
  Nevents[108341]=9997;
  Nevents[108342]=10000;
  Nevents[108343]=9950;
  Nevents[108344]=9996;
  Nevents[108345]=9996;
  Nevents[108346]=14995;
  Nevents[114010]=9969;
  double stt=(Nevents[108340]+Nevents[108341]+Nevents[108342])/3.0;
  double sts=(Nevents[108343]+Nevents[108344]+Nevents[108345])/3.0;
  Nevents[108340]=stt; Nevents[108341]=stt; Nevents[108342]=stt;
  Nevents[108343]=sts; Nevents[108344]=sts; Nevents[108345]=sts;

  //........................................

  //qcd
  Xsection[105009]=975297e4;
  Xsection[105010]=67302e4;
  Xsection[105011]=41194700;
  Xsection[105012]=2193250;
  Xsection[105013]=87848.7;
  Xsection[105014]=2328.56;
  Xsection[105015]=33.8461;
  Xsection[105016]=0.13741;
  //ttbar
  Xsection[105200]=160.79*0.556;
  Xsection[105861]=160.79*0.44444;
  //dibosons
  Xsection[105985]=44.9*0.3884;
  Xsection[105986]=5.96*0.2123;
  Xsection[105987]=18.0*0.3085;
  //W->bb
  Xsection[106280]=3.2*1.22;
  Xsection[106281]=2.6*1.22;
  Xsection[106282]=1.4*1.22;
  Xsection[106283]=0.6*1.22;
  //Z->ee
  Xsection[107650]=830.125;
  Xsection[107651]=166.2375;
  Xsection[107652]=50.2825;
  Xsection[107653]=13.9225;
  Xsection[107654]=3.615625;
  Xsection[107655]=0.9417875;
  //Z->mumu
  Xsection[107660]=830.125;
  Xsection[107661]=166.2375;
  Xsection[107662]=50.2825;
  Xsection[107663]=13.9225;
  Xsection[107664]=3.615625;
  Xsection[107665]=0.9417875;
  //Z->tautau
  Xsection[107670]=830.125;
  Xsection[107671]=166.2375;
  Xsection[107672]=50.2825;
  Xsection[107673]=13.9225;
  Xsection[107674]=3.615625;
  Xsection[107675]=0.9417875;

  //W->enu
  Xsection[107680]=6913.3*1.19887;
  Xsection[107681]=1293.0*1.19887;
  Xsection[107682]=377.1*1.19887;
  Xsection[107683]=100.9*1.19887;
  Xsection[107684]=25.3*1.19887;
  Xsection[107685]=6.9*1.19887;
  //W->munu
  Xsection[107690]=6913.3*1.19887;
  Xsection[107691]=1293.0*1.19887;
  Xsection[107692]=377.1*1.19887;
  Xsection[107693]=100.9*1.19887;
  Xsection[107694]=25.3*1.19887;
  Xsection[107695]=6.9*1.19887;
  //W->taunu
  Xsection[107700]=6913.3*1.19887;
  Xsection[107701]=1293.0*1.19887;
  Xsection[107702]=377.1*1.19887;
  Xsection[107703]=100.9*1.19887;
  Xsection[107704]=25.3*1.19887;
  Xsection[107705]=6.9*1.19887;
  //Drell-Yan
  Xsection[108319]=1252.9;
  Xsection[108320]=1253.0;
  Xsection[108321]=4407.0*0.51;
  Xsection[108322]=4406.1*0.50;
  //singletop
  Xsection[108340]=7.0;
  Xsection[108341]=7.0;
  Xsection[108342]=7.0;
  Xsection[108343]=0.468;
  Xsection[108344]=0.468;
  Xsection[108345]=0.468;
  Xsection[108346]=13.0;
  //brpv SU3
  Xsection[114010]=1.4086;

  // 
 

  esca=1.0;
  for(map<int,double>::iterator i = Xsection.begin(); i != Xsection.end(); i++){
    if(r == i->first){
      esca = L0 * Xsection[r] / Nevents[r];
      return esca;
    }
  }

  return esca;

}
